/*
 * =====================================================================================
 *
 *       Filename:  ct_semaphore.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  04/16/2015 02:25:23 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Dellinger.Zhang (mn), rainxy2000@hotmail.com
 *        Company:  TD studio
 *
 * =====================================================================================
 */

#include <assert.h>
#include <errno.h>
#include "ct_semaphore.h"

ct_semaphore::ct_semaphore()
{
	if ( sem_init( &m_hHandle, 0, 0 ) )
	assert( 0 );
}

ct_semaphore::~ct_semaphore()
{
	sem_destroy( &m_hHandle );
}

void ct_semaphore::wait()
{

	while ( 1 ) {
		if ( 0 != sem_wait( &m_hHandle ) ) {
			if ( errno == 4 )
			continue;
			else
				break;
		}
		else {
			break;
		}
	}
}

void ct_semaphore::release()
{
	if ( sem_post( &m_hHandle ) )
	assert( 0 );
}


